package com.lwisn.demo.decoding;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.lwisn.demo.filesystem.dao.DecodingDao;
import com.lwisn.demo.filesystem.dao.EncodingDao;

public class FileDecoder {
	
	private DecodingDao decodingDao;
	private InputStreamReader isr;
	private Charset charset;
	
	public Charset decode(String readPath) {
		
		ApplicationContext context = new ClassPathXmlApplicationContext(
				"spring-context.xml");
		decodingDao = (DecodingDao) context.getBean("decodingDao");
		
		isr = new InputStreamReader(decodingDao.readFile(readPath));
		
		charset = Charset.forName(isr.getEncoding());
		
		return charset;
	}

}
